﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace bxml.betterxml.xir
{

    public class XDOBuilder
    {

        public static XIRDataObject buildCharacters(String characters)
        {
            XIRDataObject xdo = new XIRDataObject(XIRDataObjectTypes.Characters, XIRDataObjectSubtypes.None);
            xdo.setBase64("cdata", characters);
            xdo.setVerbatim("length", characters.Length.ToString());
            return xdo;
        }

        public static XIRDataObject buildWhitespace(String whitespace)
        {
            XIRDataObject xdo = new XIRDataObject(XIRDataObjectTypes.Whitespace, XIRDataObjectSubtypes.None);
            xdo.setBase64("cdata", whitespace);
            xdo.setVerbatim("length", whitespace.Length.ToString());
            return xdo;
        }

        public static XIRDataObject buildStartDocument()
        {
            return new XIRDataObject(XIRDataObjectTypes.Document, XIRDataObjectSubtypes.Begin);
        }

        public static XIRDataObject buildEndDocument()
        {
            return new XIRDataObject(XIRDataObjectTypes.Document, XIRDataObjectSubtypes.End);
        }

        public static XIRDataObject buildStartElement(String nsURI, String elementName, String qualifiedName, int numOfAttributes)
        {
            XIRDataObject xdo = new XIRDataObject(XIRDataObjectTypes.Element, XIRDataObjectSubtypes.Begin);
            xdo.setVerbatim("ns", nsURI);
            xdo.setVerbatim("name", elementName);
            xdo.setVerbatim("qname", qualifiedName);
            xdo.setVerbatim("attributes", numOfAttributes.ToString());
            return xdo;
        }

        public static XIRDataObject buildEndElement(String nsURI, String elementName, String qname)
        {
            XIRDataObject xdo = new XIRDataObject(XIRDataObjectTypes.Element, XIRDataObjectSubtypes.End);
            xdo.setVerbatim("ns", nsURI);
            xdo.setVerbatim("name", elementName);
            xdo.setVerbatim("qname", qname);
            return xdo;
        }

        public static XIRDataObject buildAttribute(String nsURI, String name, String qualifiedName, String value)
        {
            XIRDataObject xdo = new XIRDataObject(XIRDataObjectTypes.Attribute, XIRDataObjectSubtypes.None);
            xdo.setVerbatim("ns", nsURI);
            xdo.setVerbatim("name", name);
            xdo.setVerbatim("qname", qualifiedName);
            xdo.setVerbatim("value", value);
            return xdo;
        }

        public static XIRDataObject buildStartPrefixMapping(String prefix, String uri)
        {
            XIRDataObject xdo = new XIRDataObject(XIRDataObjectTypes.PrefixMapping, XIRDataObjectSubtypes.Begin);
            xdo.setVerbatim("prefix", prefix);
            xdo.setVerbatim("uri", uri);
            return xdo;
        }

        public static XIRDataObject buildEndPrefixMapping(String prefix, String uri)
        {
            XIRDataObject xdo = new XIRDataObject(XIRDataObjectTypes.PrefixMapping, XIRDataObjectSubtypes.End);
            xdo.setVerbatim("prefix", prefix);
            xdo.setVerbatim("uri", uri);
            return xdo;
        }

        public static XIRDataObject buildProcessingInstruction(String target, String data)
        {
            //TODO I think something may be hosed here.
            XIRDataObject xdo = new XIRDataObject(XIRDataObjectTypes.ProcessingInstruction, XIRDataObjectSubtypes.None);
            xdo.setVerbatim("target", target);
            xdo.setVerbatim("data", data);
            return xdo;
        }

        public static XIRDataObject buildSkippedEntity(String name)
        {
            XIRDataObject xdo = new XIRDataObject(XIRDataObjectTypes.SkippedEntity, XIRDataObjectSubtypes.None);
            xdo.setVerbatim("name", name);
            return xdo;
        }
    }

}
